#include "ldroal.h"

#ifdef TEST_DBG_WIN32
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

int lo_open(const char *filename)
{
#ifdef TEST_DBG_WIN32
	HANDLE hdr = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hdr == INVALID_HANDLE_VALUE) return -1;
	return (int)hdr;
#endif
}

void lo_close(int hdr)
{
#ifdef TEST_DBG_WIN32
	CloseHandle((HANDLE)hdr);
#endif
}

int lo_seek(int hdr, unsigned int pos, int way)
{
#ifdef TEST_DBG_WIN32
	unsigned int method;
	switch (way)
	{
	case LO_SEEK_START: method = FILE_BEGIN; break;
	case LO_SEEK_CUR: method = FILE_CURRENT; break;
	case LO_SEEK_END: method = FILE_END; break;
	default: return 1;
	}
	if (SetFilePointer((HANDLE)hdr, pos, NULL, method) == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
		return 2;
	return 0;
#endif
}

unsigned int lo_filesize(int hdr)
{
#ifdef TEST_DBG_WIN32
	return GetFileSize((HANDLE)hdr, NULL);
#endif
}

#ifdef __cplusplus
}
#endif
/* EOF */
